import mysql.connector

db_config = {
    'username': 'root',
    'password': '',
    'database': 'BookDB',
    'use_unicode': True,
    'charset': 'utf8'
}


def db_query(config, sql):
    conn = mysql.connector.connect(**config)
    cursor = conn.cursor()
    cursor.execute(sql)
    result = cursor.fetchall()
    conn.close()
    return result


if __name__ == '__main__':
    sql = 'select name,price,date from book'
    result = db_query(db_config, sql)
    for name, price, date in result:
        date = date.strftime('%Y-%m-%d')
        print(f'图书：《{name}》，价格：¥{price}元，出版日期：{date}')
